<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="addMenuForm">
                        <input type="hidden" name="parentId" th:value="${parentId}" value="0">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">上级菜单：</label>
                            <div class="col-sm-8">
                                <input class="form-control" type="text" th:value="${pName}"
                                       value="根目录" readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">菜单类型：</label>
                            <div class="col-sm-8">
                                <label class="radio-inline">
                                    <input type="radio" name="type" checked value="0" /> 目录
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="type" value="1" /> 菜单
                                </label>
                                <label class="radio-inline">
                                    <input type="radio"  name="type" value="2" /> 按钮
                            </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">菜单名称：</label>
                            <div class="col-sm-8">
                                <input class="form-control" name="name" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">链接地址：</label>
                            <div class="col-sm-8">
                                <input class="form-control" name="url" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">权限标识：</label>
                            <div class="col-sm-8">
                                <input class="form-control" name="perms" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">排序号：</label>
                            <div class="col-sm-8">
                                <input class="form-control" name="orderNum"
                                       type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">图标：</label>
                            <div class="col-sm-6">
                                <input class="form-control" type="text" id="icon" name="icon"
                                       placeholder="例如：fa fa-circle-o">
                            </div>
                            <input id="ico-btn" class="btn btn-warning" type="button" value="选择图标">
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
</body>
<script>
    $.validator.setDefaults({
        submitHandler:function(){
            save();
        }
    })
    $(function(){
        //打开图标列表
        $("#ico-btn").click(function(){
            layer.open({
                type: 2,
                title:'图标列表',
                content: '/FontIcoList.html',
                area: ['480px', '90%'],
                success: function(layero, index){
                    //var body = layer.getChildFrame('.ico-list', index);
                    //console.log(layero, index);
                }
            });
        });
        $('#addMenuForm').validate({
            rules:{
                name:'required'
            },
            message:{
                name:'请输入菜单名称'
            }
        })
    })
    //数据提交到后台
    function save(){
        /*$.ajax({
            url:'/sys/menu/save',
            data:$('#addMenuForm').serialize(),
            dataType:'json',
            type:'post',
            success:function(data){
                if(data.code==200){
                    //添加成功
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                    parent.loadData();
                }else {
                    parent.layer.msg('添加失败,'+data.msg,{icon:2});
                }
            }
        });*/
        $.post("/sys/menu/save",$("#addMenuForm").serialize(),function(p){
            if(p.code==200){
                //添加成功！！
                parent.layer.close(parent.layer.getFrameIndex(window.name));
                parent.loadData();
            }else{
                //添加失败！！
                parent.layer.msg('添加失败,'+p.msg(),{icon:2});
            }
        },"json");
    }
</script>
</html>
